package eraserhead.boundary;

import javax.swing.JFrame;

import eraserhead.controller.StartRoundsController;
import eraserhead.entity.Decision;

/**
 * Form for prompting the user to wait for remaining users or to start anyways.
 */
public class StartForm extends JFrame{
	private static final long serialVersionUID = 3574893463804673145L;
	DecisionGUI parent;
	Decision model;
	
	private javax.swing.JLabel errorMsg;
    private javax.swing.JButton startBtn;
    private javax.swing.JButton waitBtn;
    
    /**
     * Create a new StartForm window
     * @param model {@link Decision} this {@link StartForm} pertains to
     * @param parent Parent {@link DecisionGUI} this {@link StartForm} is for
     */
	public StartForm(Decision model, DecisionGUI parent) {
		this.model = model;
		this.parent = parent;
		initComponents();
	}
	
	public void initComponents() {
        errorMsg = new javax.swing.JLabel();
        waitBtn = new javax.swing.JButton();
        startBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        setMaximumSize(new java.awt.Dimension(320, 240));
        setMinimumSize(new java.awt.Dimension(320, 240));
        setPreferredSize(new java.awt.Dimension(320, 240));

        errorMsg.setFont(new java.awt.Font("Felix Titling", 0, 14)); // NOI18N
        errorMsg.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        errorMsg.setText("Not all users are here.");
        errorMsg.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        waitBtn.setFont(new java.awt.Font("Felix Titling", 0, 11)); // NOI18N
        waitBtn.setText("Wait for others");
        waitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	StartForm.this.dispose();
            }
        });

        startBtn.setFont(new java.awt.Font("Felix Titling", 0, 11)); // NOI18N
        startBtn.setText("Start Anyway");
        startBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	new StartRoundsController(model, parent).processAnyway();
            	StartForm.this.dispose();
            }
        });
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(30, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(waitBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(startBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(errorMsg, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(errorMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(waitBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(startBtn)
                .addContainerGap(66, Short.MAX_VALUE))
        );
        pack();
    }
}
